package com.woniuxy01;

import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-05-27 9:27
 */
public class Test00 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String answer;
        int userShow=0;
        String userShowName="";
        int computerShow=0;
        String computerShowName="";

        int count=0;
        int userWin=0;
        int computerWin=0;
        //开始游戏
        do {
            count++;
            //用户出拳
            boolean flag;
            do {
                flag = true;
                if (flag) {
                    System.out.println("玩家出拳,1.剪刀；2.石头3.布");
                } else {
                    System.out.println("出拳错误，只能输入1，2，3：1.剪刀；2.石头3.布");
                }
                userShow = sc.nextInt();
                if (!(userShow == 1 || userShow == 2 || userShow == 3)) {
                    flag = false;
                }
            } while (!flag);
            //显示用户出拳
            switch (userShow) {
                case 1:
                    userShowName = "剪刀";
                    break;
                case 2:
                    userShowName = "石头";
                    break;
                case 3:
                    userShowName = "布";
                    break;
            }
            //电脑出拳
            computerShow=(int)(Math.random()*100)%3+1;
            //显示电脑出拳
            switch (computerShow) {
                case 1:
                    computerShowName = "剪刀";
                    break;
                case 2:
                    computerShowName = "石头";
                    break;
                case 3:
                    computerShowName = "布";
                    break;
            }
            System.out.println("用户输入："+userShowName);
            System.out.println("电脑输入："+computerShowName);
            //判断胜负
            if((userShow==1&&computerShow==3)||(userShow==2&&computerShow==1)||(userShow==3&&computerShow==2)){
                userWin++;
                System.out.println("用户获胜");
            }else if(userShow==computerShow){
                System.out.println("平局");
            }else{
                computerWin++;
                System.out.println("电脑获胜");
            }
            System.out.println("是否继续下一局");
            answer = sc.next();
        } while (answer.equals("y"));
        //总成绩:最终胜负
        System.out.println("对战次数:"+count);
        System.out.println("用户获胜:"+userWin);
        System.out.println("电脑获胜:"+computerWin);
        if(userWin>computerWin){
            System.out.println("用户最终获胜");
        }else if(computerWin>userWin){
            System.out.println("电脑最终获胜");
        }else{
            System.out.println("打平");
        }
        System.out.println("游戏结束");
    }



}
